package com.ruoyi.serve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.serve.domain.Serve;
import com.ruoyi.serve.service.IServeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 服务调查管理Controller
 *
 * @author ruoyi
 * @date 2023-04-08
 */
@RestController
@RequestMapping("/serve/serve")
public class ServeController extends BaseController
{
    @Autowired
    private IServeService serveService;

    /**
     * 导入数据
     * */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Serve> util = new ExcelUtil<Serve>(Serve.class);
        List<Serve> serves = util.importExcel(file.getInputStream());
        for (int i = 0; i < serves.size(); i++) {
            Serve serve = serves.get(i);
            serveService.insertServe(serve);
        }
        return AjaxResult.success();
    }

    /**
     * 查询服务调查管理列表
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:list')")
    @GetMapping("/list")
    public TableDataInfo list(Serve serve)
    {
        startPage();
        List<Serve> list = serveService.selectServeList(serve);
        return getDataTable(list);
    }

    /**
     * 导出服务调查管理列表
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:export')")
    @Log(title = "服务调查管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Serve serve)
    {
        List<Serve> list = serveService.selectServeList(serve);
        ExcelUtil<Serve> util = new ExcelUtil<Serve>(Serve.class);
        util.exportExcel(response, list, "服务调查管理数据");
    }



    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<Serve> util = new ExcelUtil<Serve>(Serve.class);
        return util.importTemplateExcel("用户数据");
    }


    /**
     * 获取服务调查管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:query')")
    @GetMapping(value = "/{serveId}")
    public AjaxResult getInfo(@PathVariable("serveId") Integer serveId)
    {
        return success(serveService.selectServeByServeId(serveId));
    }

    /**
     * 新增服务调查管理
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:add')")
    @Log(title = "服务调查管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Serve serve)
    {
        System.out.println();
        return toAjax(serveService.insertServe(serve));

    }

    /**
     * 修改服务调查管理
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:edit')")
    @Log(title = "服务调查管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Serve serve)
    {
        return toAjax(serveService.updateServe(serve));
    }

    /**
     * 删除服务调查管理
     */
    @PreAuthorize("@ss.hasPermi('serve:serve:remove')")
    @Log(title = "服务调查管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serveIds}")
    public AjaxResult remove(@PathVariable Integer[] serveIds)
    {
        return toAjax(serveService.deleteServeByServeIds(serveIds));
    }
}
